var groupId = 34;
var houseNumberId = 44;
var buildingId = 50;
var unitId = 51;
var roomId = 53;
var groupName = "组";
var houseNumberName = "号";
var buildingName = "幢";
var unitName = "单元";
var roomName = "室";

function checkForm() {
    var addressElementType = $("#addressElementType").val().trim();
    var addressElementName = $("#addressElementName").val().trim();
    var latlngs = $("#latlngs").val().trim();
    var lng = $("#lng").val().trim();
    var lat = $("#lat").val().trim();
    if (addressElementType == "") {
        layer.msg("请选择元素类型");
        $("#addressElementType").focus();
        return false;
    }
    if (addressElementName == "") {
        layer.msg("请输入元素名称");
        $("#addressElementName").focus();
        return false;
    }
    if (addressElementType == groupId) {
        if (!checkIfNumber(addressElementName)) {
            layer.msg("元素名称只能输入数字");
            return false;
        }
    }
    if (addressElementType == houseNumberId || addressElementType == buildingId
        || addressElementType == unitId || addressElementType == roomId) {
        if (!checkIfNumber(addressElementName)) {
            layer.msg("元素名称只能输入数字");
            return false;
        }
        if (lng == "" || lat == "") {
            layer.msg("请输入经纬度坐标信息");
            $("#mapDiv").focus();
            return false;
        }
    }
    if (isNotNull(info) && addressElementName == info.addressElementName && lat == info.lat && lng == info.lng && latlngs == info.latlngs) {
        layer.msg("请先修改相应信息后再进行保存");
        return false;
    }
    return true;
}

function checkIfNumber(val) {
    var reg = /^[0-9]+$/;//判断是否为数字
    if (!reg.test(val)) {
        return false;
    }
    return true;
}

function checkType(val) {
    var name = getNameByType(val);
    $("#unitName").html(name);
}

function getNameByType(val) {
    var name = "";
    if (val == groupId) {
        name = groupName;
    } else if (val == houseNumberId) {
        name = houseNumberName;
    } else if (val == buildingId) {
        name = buildingName;
    } else if (val == unitId) {
        name = unitName;
    } else if (val == roomId) {
        name = roomName;
    }
    return name;
}